import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        a0301: props.values.a0301,
        zc9993: props.values.zc9993,
        a0303: props.values.a0303,
        a0304: props.values.a0304,
        a0307_1: props.values.a0307_1,
        a0307_2: props.values.a0307_2,
        a0311: props.values.a0311,
        a0314: props.values.a0314,
        a0317: props.values.a0317,
        a0318: props.values.a0318,
        a0219: props.values.a0317,
        a0319: props.values.a0319,
        a0320: props.values.a0320

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			} */

			if(formVals.a0303) {
      			formVals.a0303 = moment(formVals.a0303._d).format("YYYY-MM-DD");
      		}
      if(formVals.a0304) {
      			formVals.a0304 = moment(formVals.a0304._d).format("YYYY-MM-DD");
      		}
      if(formVals.a0317) {
      			formVals.a0317 = moment(formVals.a0317._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file;
			handleSubmitSubsetInfo(formVals,"update_for_staff_jobGradeInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="职务层次">
			              {getFieldDecorator('a0301', {
			              rules: [{ required: true, message: '请输入1-10个字符',max: 10}],
			              initialValue: formVals.a0301,
			              })(
                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                    	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                    		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                    	}):null}
                    </Select>
                    )}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="状态">
                    {getFieldDecorator('a0314', {
                      rules: [{ required: true, message: '请选择'}],
                      initialValue: formVals.a0314,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="起算日期">
			              {getFieldDecorator('a0304',{
			              	initialValue: formVals.a0304?moment(formVals.a0304):null,
			              	})(
			              	<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>,
			              	)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="是否高配">
			              {getFieldDecorator('a0319', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a0319,
			              })(
                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                    	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                    		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                    	}):null}
                    </Select>
                    )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="变动原因">
			              {getFieldDecorator('a0318', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a0318,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              	  	{dicListByPcode('YT') != undefined?dicListByPcode('YT').map((item,index) => {
			              	  		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              	  	}):null}
			              	  </Select>
			              )}
			          </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="批准文号">
			              {getFieldDecorator('a0311',{
			                rules: [{ required: false, message: '请选择！'}],
                      initialValue: formVals.a0311,
			              })(
			              	<Input placeholder="1-40个字符" />
			              )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="批准机关名称">
			              {getFieldDecorator('a0307_1', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a0307_1,
			              })(
                      <Input placeholder="1-40个字符" />
                    )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="批准机关代码">
			              {getFieldDecorator('a0307_2', {
                    rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a0307_2,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="批准日期">
			              {getFieldDecorator('a0303', {
			              rules: [{ required: false, message: '请选择' }],
			              initialValue: formVals.a0303?moment(formVals.a0303):null,
                    })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
			          </FormItem>
			        </Col>

			       	<Col  md={12} sm={24}>
			       	  <FormItem  label="终止日期">
			       	      {getFieldDecorator('a0317', {
			       	        rules: [{ required: false, message: '请选择'}],
                      initialValue: formVals.a0317?moment(formVals.a0317):null,
                          })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
                      </FormItem>
			       	</Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


            <Col md={12} sm={24}>
              <FormItem  label="职务层次备注">
                  {getFieldDecorator('a0320', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a0320,
                    })(
                    <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          	<Col md={12} sm={24}>
                  <Button
                  	size="large"
                  	style={{marginRight: '10px'}}
                  	onClick={()=> {
                  		const { form } = this.props;
          				form.resetFields();
                  		cancelEditJobInfo(spinIndex);
                  	}}>
                  	取消
                 	</Button>
                  <Button size="large" type="primary" htmlType="submit">保存</Button>
              </Col>
          </Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="职务层次">
			              {getFieldDecorator('a0301')(<span>{formVals.a0301}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="状态">
			              {getFieldDecorator('a0314')(<span>{formVals.a0314}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="起算日期">
			              {getFieldDecorator('a0304')(<span>{formVals.a0304?moment(formVals.a0304).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="是否高配">
			              {getFieldDecorator('a0319')(<span>{formVals.a0319}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="变动原因">
			              {getFieldDecorator('a0318')(<span>{formVals.a0318}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="批准文号">
			              {getFieldDecorator('a0311')(<span>{formVals.a0311}
			              	</span>)}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="批准机关名称">
			              {getFieldDecorator('a0307_1')(<span>{formVals.a0307_1}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="批准机关代码">
			              {getFieldDecorator('a0307_2')(<span>{formVals.a0307_2}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="批准日期">
			              {getFieldDecorator('a0303')(<span>{formVals.a0303?moment(formVals.a0303).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="终止日期">
			              {getFieldDecorator('a0317')(<span>{formVals.a0317?moment(formVals.a0317).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="职务层次备注">
			              {getFieldDecorator('a0320')(<span>{formVals.a0320}
			              </span>)}
			          </FormItem>
			        </Col>

			    </Row>

			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
